package com.trippin.DB.entities;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.gson.annotations.Expose;

@PersistenceCapable
public class Comment implements TrippinEntity, Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	Key key;
	
	@Persistent
	@Expose
	long id;
	
	@Persistent
	@Expose
	long userId;

	@Persistent
	@Expose
	Date date;
	
	@Persistent
	@Expose
	String comment;
	
	public Comment() {}
	
	public Comment(long userId, String comment, Date date) {
		this.userId = userId;
		this.comment = comment;
		this.date = date;
		this.id = -1;
	}

	public long getId() {
		if(id < 0)
			id = key.getId();
		return id;
	}


	public void setId() {
		id = key.getId();
	}

	public long getUserId() {
		return userId;
	}
	
	public void setUserId(long userId) {
		this.userId = userId;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(this == obj)
			return true;
		if(!(obj instanceof Comment))
			return false;
		
		Comment com = (Comment)obj;
		if(this.userId != com.getUserId())
			return false;
		if(!this.date.equals(com.getDate()))
			return false;
		if(!(this.comment.equalsIgnoreCase(com.getComment())))
			return false;
		
		return true;
		
	}

	public Comment createNewComment(long user, Comment comm) {
		return new Comment(user, comm.getComment(),new Date());
	}

}
